using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;
using BUS;
using Utility;
public partial class Admin_SanPhamDetail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            load_data();
    } 
    private void load_data()
    {

        int iD=int.Parse (Request .QueryString ["id"].ToString ());
        tbSanPham sanPham = tbSanPhamBUS.GetId(iD);
        lit_MaSP.Text = sanPham.IdSanPham.ToString();
        lit_TenSP.Text = sanPham.TenSP.ToString();
        
        tbLoaiSP loaiSP=tbLoaiSPBUS .GetId (int.Parse (sanPham .IdLoaiSP .ToString ()));
        lit_Loai .Text =loaiSP .TenLoai .ToString ();

        tbDiaDiem diaDiem=tbDiaDiemBUS .GetById (int.Parse (sanPham .IdDiaDiem .ToString ()));
        lit_DiaDiem .Text =diaDiem .TenDiaDiem .ToString ();

        tbTrangThaiSP trangThaiSP = tbTrangThaiSPBUS.GetById(int.Parse (sanPham.IdTrangThaiSP.ToString()));
        lit_TrangThaiSP.Text = trangThaiSP.TenTrangThai.ToString();

        tbNhanVien nhanVien = tbNhanVienBUS.GetId(int.Parse (sanPham.IdNhanVien.ToString()));
        lit_NhanVien.Text = nhanVien.TenNhanVien.ToString();

        tbDoanhNghiep doanhNghiep = tbDoanhNghiepBUS.GetById(int.Parse (sanPham.IdDoanhNghiep.ToString()));
        lit_DoanhNghiep.Text = doanhNghiep.TenDoanhNghiep.ToString();

        lit_GiaBan.Text = sanPham.GiaBan.ToString();
        lit_GiaTriThuc.Text = sanPham.GiaTriThuc.ToString();
        txt_DKSuDung.Text = sanPham.DKSungDung.ToString();
        txt_MoTa.Text = sanPham.MoTa.ToString();
        lit_SLBan.Text = sanPham.SLBan.ToString();
        lit_SLDaBan.Text = sanPham.SLDaBan.ToString();
        lit_NgayBDBan.Text = sanPham.NgayBDBan.ToString("dd-MM-yyyy");
        lit_NgayKTBan.Text = sanPham.NgayKTBan.ToString("dd-MM-yyyy");
        lit_NgayCapNhat.Text = sanPham.NgayUpdate.ToString("dd-MM-yyyy");
        lit_NgayDNBan.Text = sanPham.NgayDNBan.ToString("dd-MM-yyyy");
        lit_TLHoaHong.Text = sanPham.TLHoaHong.ToString() + " %";

        int Total = 0;
        Criteria Cri = new Criteria();
        Cri.add(Condition.AND, tbHinhAnhColumns.IdSanPham, Condition.EQUAL, sanPham.IdSanPham.ToString());
        tbHinhAnhCollection hinhAnhCollection = tbHinhAnhBUS.Get(Cri.Criter, PagerV2_8_1 .CurrentIndex , PagerV2_8_1 .PageSize ,
                                                                 tbHinhAnhColumns.IdHinhAnh.ToString(),
                                                                 OrderDirection.ASC.ToString(), out Total);
        Repeater1.DataSource = hinhAnhCollection;
        Repeater1.DataBind();
        PagerV2_8_1.ItemCount = Total;
        if (PagerV2_8_1.ItemCount <= PagerV2_8_1.PageSize)
            PagerV2_8_1.Visible = false;
        else
            PagerV2_8_1.Visible = true;
    }
    protected void pager_Command(object sender, CommandEventArgs e)
    {
        PagerV2_8_1.CurrentIndex = int.Parse(e.CommandArgument.ToString());
        load_data ();
    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if(e.Item .ItemType ==ListItemType .AlternatingItem ||
            e.Item .ItemType == ListItemType .Item )
        {
            tbHinhAnh hinhAnh = (tbHinhAnh)e.Item.DataItem;

            Literal lit_Hinh = (Literal)e.Item.FindControl("lit_Hinh");
            lit_Hinh.Text   = hinhAnh .TenHinh  .ToString () ;

            Image img_HinhAnh = (Image)e.Item.FindControl("img_HinhAnh");
            img_HinhAnh.ImageUrl = "~/Photos/Thumb/" + hinhAnh.TenHinh.ToString();
        }
    }
}
